/*
package com.study.service.impl;

import com.study.entity.Command;
import com.study.service.IRedisService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

*/
/**
 * @author mjy
 * @date 2021/12/07
 * @description
 *//*

public class IRedisServiceImpl implements IRedisService {

    @Resource
    private RedisTemplate<Object, Object> redisTemplate;


    @Override
    public void setKey(String key, Object value, long timeout, TimeUnit timeUnit) {
        ValueOperations<Object, Object> ops = redisTemplate.opsForValue();
        ops.set(key, value);
        if (timeout > 0)
            redisTemplate.boundValueOps(key).expire(timeout, timeUnit);
    }

    @Override
    public Object getValue(String key) {
        ValueOperations<Object, Object> ops = redisTemplate.opsForValue();
        return ops.get(key);
    }

    @Override
    public void deleteKey(String key) {
        redisTemplate.delete(key);
    }

    @Override
    public void saveCommand(String imei, String commandNumber,Object object ) {
        //用指令前缀加上imei号存储一个map。map中存放的是每条指令的流水号为key，value是一个对象，对象中存放指令内容和状态
        String key=Constants.COMMAND_PREFIX+imei;
        Map<Object, Object> map = redisTemplate.opsForHash().entries(key);
        if(map==null){
            map=new HashMap<>();
        }
        map.put(commandNumber,object);
        redisTemplate.opsForHash().putAll(Constants.COMMAND_PREFIX+imei,map);

    }

    @Override
    public Map<String, Object> getCommandsByImei(String imei) {
   */
/*     ValueOperations<Object, Object> ops = redisTemplate.opsForValue();
        Map<String,Object> commandMap = (Map<String,Object>)ops.get(Constants.COMMAND_PREFIX+imei);*//*

        Object commandMap =redisTemplate.opsForHash().entries(Constants.COMMAND_PREFIX+imei);
        if(commandMap!=null){
            return (Map<String,Object>)commandMap;
        }
        return null;
    }

    @Override
    public boolean isDeviceOnline(String imei) {
        return redisTemplate.hasKey(Constants.DEVICE_ONLINE_PREFIX+imei);
    }

    @Override
    public void refreshDeviceOnlineTime(String imei,long timeout,TimeUnit timeUnit) {
        redisTemplate.boundValueOps(Constants.DEVICE_ONLINE_PREFIX+imei).expire(timeout, timeUnit);
    }

    @Override
    public void deleteCommand(String imei, String commandNumber) {
        String key = Constants.COMMAND_PREFIX + imei;
        Object map =  redisTemplate.opsForHash().entries(key);
        if (map != null) {
            redisTemplate.opsForHash().delete(key,commandNumber);
        }
    }

    @Override
    public void updateCommand(String imei, String commandNumber, Command command) {
        redisTemplate.opsForHash().put(imei,commandNumber,command);
    }

   */
/* @Override
    public Map<String, Object> getUnInStorageDevice() {
        Object commandMap =redisTemplate.opsForHash().entries(Constants.UN_STORAGE_DEVICE);
        if(commandMap!=null){
            return (Map<String,Object>)commandMap;
        }
        return null;
    }*//*

}
*/
